package magicbox;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;

/**
 *
 * @author Mikael Köhlmyr | mikael@kohlmyr.com | http://www.kmyr.net
 */
public abstract class Screen extends JPanel {

        public static int WIDTH, HEIGHT;
        private BufferedImage buffer;
        public Graphics bufferg;

        public Screen() {
                super();
                
                //super.setPreferredSize(new Dimension(Screen.WIDTH, Screen.HEIGHT));
        }

        public void configure() {
                // load img for bg etc
                this.buffer = new BufferedImage(Screen.WIDTH, Screen.HEIGHT, BufferedImage.TYPE_INT_ARGB);
                this.bufferg = buffer.createGraphics();
                super.setPreferredSize(new Dimension(Screen.WIDTH, Screen.HEIGHT));
        }

        public void update() {
                new Thread(new PaintManager()).start();
        }

        @Override
        public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g = (Graphics2D) g;
                g.drawImage(buffer, 0, 0, this);
        }

        public abstract void draw(Graphics g);

        private class PaintManager implements Runnable {

                @Override
                public void run() {
                        draw(bufferg);
                        repaint();
                }
        }
}